﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerFrame;
using Protocol;
using Gameserver.Logic.Login;
using Gameserver.Logic.Match;

namespace Gameserver
{
    /// <summary>
    /// 消息处理中心，负责消息的分发处理
    /// </summary>
    public class HanderCenter:AbsMessageCenter
    {
        IMessageHandler login;//登陆接口
        IMessageHandler match;//房间接口
        public HanderCenter()
        {
            login = new LoginHandler();
            match = new MatchHandler();
        }
        public override void OnClientConnected(Mytoken token)
        {
            Console.WriteLine("有客户连接"+token.socket.AddressFamily);
            login.OnClientConnected(token);
            match.OnClientConnected(token);
        }
        public override void OnClientClose(Mytoken token, string error)
        {
            Console.WriteLine("有客户端断开连接");
            match.OnClientClose(token, error);
            login.OnClientClose(token, error);
        }
        public override void OnMessageRecive(Mytoken token, TransModel model)
        {
            //判断model.type 根据协议分配model
            //switch()
            if (model == null)
                return;
            switch (model.type)
            {
                case GameProtocol.login:
                    login.OnMessageRecive(token, model);
                    break;
                case GameProtocol.match:
                    match.OnMessageRecive(token, model);
                    break;
                default:
                break;
            }
        }
    }
}
